angular.module('tab-order-list', [])

.controller 'TabOrderListCtrl', (Toast,$location, $localStorage, $ionicLoading, $scope, $state,$http, $window, $ionicHistory,$stateParams, orderService, ListDataService, $ionicScrollDelegate,$filter) ->

  orderListSrv = ListDataService.get('orderList')
  orderListSrv.watch (orderDatas) ->
    $scope.orderList = orderDatas

  _.extend $scope,
    canLoadMore: () ->
      console.log(orderListSrv.canLoadMore())
      orderListSrv.canLoadMore()

    doRefresh: ->
      console.log 'reload'
      orderListSrv.reload({when: 2}, true).finally ->
        console.log 'load end'
        $scope.$broadcast 'scroll.refreshComplete'

    loadMore: ->
      console.log 'loadMore'
      orderListSrv.loadMore({when: 2}, true).finally -> $scope.$broadcast 'scroll.infiniteScrollComplete'

    toDetail: (orderId)->
      $state.go('tab.orderDetail', {id: orderId})

  $scope.doRefresh()